﻿<cfsilent>
	<cfscript>
		
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		
		event.setArg("pageTitle", "教学质量评价");
		
		/* 学期相关信息 */
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		termDateStart = event.getArg("DateStart");
		
		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		/* 网上评教相关设置 */
		dateStart = event.getArg("EVALSYS.STU.DateStart");
		dateEnd = event.getArg("EVALSYS.STU.DateEnd");
		//stuMarkView = event.getArg("EVALSYS.STU.DisableMarkView");
		
		/* 当前日期 */
		dateNow = datetimeAdvice.getCurrentDateString();
		
		/* 计算当前教学周 */
		currentWeek = mathAdvice.convertTaskWeek( termDateStart, dateNow );

		evsId = event.getArg("ES");
		chooserId = event.getArg("SCC");
		secureTicket = event.getArg("ST");
		
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		/* 安全设置 */
		voteSecure = false;
		voteAllowed = false;
		
		/* 首先做安全检查 */
		try {
			stringOrignal = decrypt( secureTicket, studentId, "PBEWithMD5AndDES", "Hex");
			stringTest = evsId & chooserId & taskType & taskId;
			
			if ( stringOrignal eq stringTest ) {
				voteSecure = true;
			}
		}
		catch(any excpt) {
		}
		
		if ( voteSecure ) {
			
			/* 是否在可评教时间 */
			if ( dateNow GTE dateStart AND dateNow LTE dateEnd ) {
				
				voteAllowed = true;
				
			}
			
		}
		if ( voteAllowed ) {
			
			/* 评价体系相关设置 */
			sql = "SELECT 
					es_name, es_model, es_level 
					FROM t_evaluate_system 
					WHERE 
						es_id = :evsId ";
		
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="evsId", value=evsId, cfsqltype="cf_sql_char" );

			rs_evs = queryObj.execute( sql=sql ).getResult();
			
			
			/* 读取教学班信息 */
			switch ( taskType ) {
				
				case "P":
					sql = "SELECT 
							a.task_week, b.cid, b.course_name, c.tch_id, c.tch_name, d.institute_name 
							FROM t_task a 
							INNER JOIN t_course b ON b.cid = a.cid 
							INNER JOIN t_teacher c ON c.tch_id = a.tch_id 
							INNER JOIN t_institute d ON d.institute_id = b.institute_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
				
				case "C":
					sql = "SELECT 
							a.task_week, b.cid, b.course_name, c.tch_id, c.tch_name, d.institute_name 
							FROM t_common_task a 
							INNER JOIN t_course b ON b.cid = a.cid 
							INNER JOIN t_teacher c ON c.tch_id = a.tch_id 
							INNER JOIN t_institute d ON d.institute_id = b.institute_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;

				case "T":
					sql = "SELECT 
							a.task_week, b.cid, b.course_name, c.tch_id, c.tch_name, d.institute_name 
							FROM t_sport_task a 
							INNER JOIN t_course b ON b.cid = a.cid 
							INNER JOIN t_teacher c ON c.tch_id = a.tch_id 
							INNER JOIN t_institute d ON d.institute_id = b.institute_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;

				case "R":
					sql = "SELECT 
							a.task_week, b.cid, b.course_name, c.tch_id, c.tch_name, d.institute_name 
							FROM t_reopen_task a 
							INNER JOIN t_course b ON b.cid = a.cid 
							INNER JOIN t_teacher c ON c.tch_id = a.tch_id 
							INNER JOIN t_institute d ON d.institute_id = b.institute_id 
							WHERE 
								a.tsk_id = :taskId ";
					break;
			}
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );

			rs_task = queryObj.execute( sql=sql ).getResult();
			
			targetNeed = 0;
			targetDone = 0;
			
			/* 两段式评教 */
			writeLog( text=rs_evs.es_model  );
			if ( rs_evs.es_model eq "M2" ) {
				
				wk1 = listFirst( rs_task.task_week, "-" );
				wk2 = listLast( rs_task.task_week, "-" );
				
				/* 课程运行两周后允许评教 */
				if ( currentWeek - wk1 gt 2 ) {
					showStage = 1;
				} 
				else {
					voteAllowed = false;
				}
				
				/* 课程已结束 允许完成第二段评教 */
				if ( currentWeek gt wk2 ) {
					showStage = 2;
				}
				
			}
			
			
			/* 评价体系观测点 */
			sql = "SELECT 
					level_order, tag_id, tag_order, tag_weight, question, 
					t_measure_set.m_id, t_measure_set.measure 
					FROM t_target 
					INNER JOIN t_measure_set ON t_measure_set.m_id = t_target.m_id 
					WHERE 
						es_id = :evsId ";
		
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="evsId", value=evsId, cfsqltype="cf_sql_char" );
		
			rs_target = queryObj.execute( sql=sql ).getResult();
		
		
			/* 评价体系选项 */
			sql = "SELECT m_id, opt_name, opt_idx FROM t_measure_options ";
												
			queryObj = new Query( datasource=application.dnsSlave );
		
			rs_options = queryObj.execute( sql=sql ).getResult();
			
			
			/* 生成已投票选项 */
			sql = "SELECT tag_id, answer, locked FROM t_target_response WHERE scc_id = :chooserId ";
			
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="chooserId", value=chooserId, cfsqltype="cf_sql_varchar" );
		
			rs_response = queryObj.execute( sql=sql ).getResult();
			
			savedOpts = structNew();
		
			for( a=1; a LTE rs_response.recordCount; a++ ){
				
				/* 已投票计数累加 */
				targetDone++;
				
				structInsert( savedOpts, "OPT" & rs_response['tag_id'][a], rs_response['answer'][a], true );
				structInsert( savedOpts, "LOCK" & rs_response['tag_id'][a], rs_response['locked'][a], true );
				
			}
			
		}
		
		currentTab = event.getArg("TabID", "labDetail");

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">

			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教学质量评价
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="findStudent">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labDetail">class="active"</cfif> id="labDetail" tabTarget="Detail">教学质量评价问卷</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
				
					});
					// -->
					//]]>
				</script>
				
				<div id="Detail" class="tabContent">
					
					<cfif voteAllowed>
							
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								
								$(document).ready(function() {
									
									/* 生成匿名问卷 */
									$.blockUI({ 
										message: '正在生成匿名的教学质量评价问卷, 请稍后...',
										css: { 
												'width': '22%',
												'left': '42%',
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#333', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#fff',
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#000', 
												'opacity': .1 ,
												'cursor': null
												}
										});
										
									
									/* 显示匿名评价表 */
									$('body').oneTime('3s',function(){

										$("div#sheetNotice").removeClass("hidden_elem");
										$("table#sheetTable").removeClass("hidden_elem");
										
										/* 取消阻挡 */
										$.unblockUI();
										
									});
									
								});

								// -->
								//]]>
							</script>
							
							

							<div class="noticeBlock">
								<h2>《<cfoutput>#rs_task.course_name#</cfoutput>》- 主讲教师: <cfoutput>#rs_task.tch_name#</cfoutput></h2>
								<p><span class="img icon16x16 message"></span>任课单位: <cfoutput>#rs_task.institute_name#</cfoutput> </p>
								<hr/>
							</div>
							
							<div id="sheetNotice" class="systemNotice hidden_elem">
								<p><span class="img icon16x16 info"></span>各位同学，此处提交的各类评分、问卷及建议均为匿名信息，请根据实际情况对任课教师的教学工作作出客观、公正的评价。</p>
							</div>
						
							<!--- 两段式评教 --->
							<cfif rs_evs.es_model eq "M2">
								
								<cfset L1 = 0 />
								<!---<div id="out"></div>--->
								
								<table id="sheetTable" class="UItable hidden_elem">
								
									<cfloop from="1" to="#showStage#" index="stageId">

										<cfscript>
							
											sql = "SELECT tag_order, question, tag_weight FROM query WHERE level_order = :stageId AND tag_order LIKE '__00' ORDER BY tag_order ";
							
											queryObj = new Query( dbtype="query" );
											queryObj.setAttributes( query=rs_target );
											queryObj.addParam( name="stageId", value=stageId, cfsqltype="cf_sql_char" );

											rs_type = queryObj.execute( sql=sql ).getResult();

										</cfscript>
								
										<cfif rs_type.recordCount>
									
											<cfif stageId gt 1>
												<tr class="breakRows">
													<td colspan="2"></td>
												</tr>
											</cfif>
											<tr class="cellBorder cellHeader">
												<td colspan="2">
												<cfif stageId eq 1>
													课程进行期间
													<cfelse>
													课程结束后
												</cfif>
												</td>
											</tr>
											<tr class="breakRows">
												<td colspan="2"></td>
											</tr>
										</cfif>
										
										
										<cfloop query="rs_type">
											
											<cfset L1++ />
											
											<tr class="cellBorder cellNotice">
												<td><span class="numeric"><cfoutput>#L1#</cfoutput></span></td>
												<td><cfoutput>#rs_type.question#</cfoutput></td>
											</tr>
									
											<cfscript>
									
												sql = "SELECT tag_id, question, m_id, measure FROM query WHERE level_order = :stageId AND tag_order NOT LIKE '__00' AND tag_order LIKE :condition ORDER BY tag_order ";
							
												queryObj = new Query( dbtype="query" );
												queryObj.setAttributes( query=rs_target );
												queryObj.addParam( name="stageId", value=stageId, cfsqltype="cf_sql_char" );
												queryObj.addParam( name="condition", value=left(rs_type.tag_order, 2) & "__", cfsqltype="cf_sql_char" );

												rs_list = queryObj.execute( sql=sql ).getResult();
										
											</cfscript>
									
											<cfif rs_list.recordCount>
											
												<cfset L2 = 0 />

												<cfloop query="rs_list">
													
													<cfset L2++ />
													<cfset targetNeed++ />
													
													<cfscript>
														
														targetId = rs_list.tag_id;
														measureId = rs_list.m_id;
														measure = rs_list.measure;
														
														if ( measure eq "L" ) {
															
															sql = "SELECT opt_name FROM query WHERE m_id = :measureId ORDER BY opt_idx";
							
															queryObj = new Query( dbtype="query" );
															queryObj.setAttributes( query=rs_options );
															queryObj.addParam( name="measureId", value=measureId, cfsqltype="cf_sql_char" );

															rs_opt = queryObj.execute( sql=sql ).getResult();

														}
														
														
													</cfscript>
													
													<cfif measure eq "L" >

														<tr class="cellBorder">
															<td rowspan="2"><span class="numeric"><cfoutput>#L1#</cfoutput>.<cfoutput>#L2#</cfoutput></span></td>
															<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_list.question )#</cfoutput></td>
														</tr>
														<tr class="cellBorder">
															<td class="quota ltr" rowid="<cfoutput>#targetId#</cfoutput>">
																<cfset opt = 0 />
																<cfloop query="rs_opt">
																	
																	<cfset opt++ />
																	
																	
																	<cfif structKeyExists(savedOpts, "LOCK" & targetId) and savedOpts["LOCK" & targetId] eq "1">
																			<!--- 已提交 且已锁定 --->
																			<span <cfif structKeyExists(savedOpts, "OPT" & targetId) and savedOpts["OPT" & targetId] eq opt>class="checked"</cfif>><cfoutput>#rs_opt.opt_name#</cfoutput></span>
																		<cfelse>
																			<!--- 没有提交评价记录 --->
																			<cfset sign = encrypt( targetId & opt, studentId, "PBEWithMD5AndDES", "Hex") />
																			<a data-opt="<cfoutput>#opt#</cfoutput>" <cfif structKeyExists(savedOpts, "OPT" & targetId) and savedOpts["OPT" & targetId] eq opt>class="checked"</cfif> href="javascript:postQuota('<cfoutput>#targetId#</cfoutput>','<cfoutput>#opt#</cfoutput>','<cfoutput>#sign#</cfoutput>');"><cfoutput>#rs_opt.opt_name#</cfoutput></a>
																	</cfif>
																	
																</cfloop>
															</td>
														</tr>
													
													</cfif>
													
													<cfif measure eq "M" >
														
														<tr class="cellBorder">
															<td><span class="numeric"><cfoutput>#L1#</cfoutput>.<cfoutput>#L2#</cfoutput></span></td>
															<td class="quota ltr">
																<cfset sign = encrypt( targetId, studentId, "PBEWithMD5AndDES", "Hex") />
																<cfoutput>#stringAdvice.XHTMLSafeFormat( rs_list.question )#</cfoutput>
																<input onBlur="postScroll('<cfoutput>#targetId#</cfoutput>','<cfoutput>#sign#</cfoutput>');" class="Mark" type="text" name="Mark<cfoutput>#targetId#</cfoutput>" id="Mark<cfoutput>#targetId#</cfoutput>" />
															</td>
														</tr>
														
													</cfif>
											
												</cfloop>
										
											</cfif>
									
										</cfloop>
								
									</cfloop>
									
									<tr class="breakRows">
										<td colspan="2"></td>
									</tr>
									<tr class="cellBorder cellHeader">
										<td colspan="2">针对该门课程任课教师 或 课堂教学过程，您的意见和建议</td>
									</tr>
									<tr class="breakRows">
										<td colspan="2"></td>
									</tr>
									<tr class="cellBorder">
										<td></td>
										<td>
											<form id="formComment" onSubmit="javascript:return processVerfiyForm('formComment');" class="formWrapper Transparent Mini" method="post" action="<cfoutput>#buildURL('evaluateResponseDo')#</cfoutput>">
												
												<input type="hidden" name="Mode" value="M2" />
												<input type="hidden" name="Stage" value="<cfoutput>#showStage#</cfoutput>" />
												<input type="hidden" name="TeacherID" value="<cfoutput>#rs_task.tch_id#</cfoutput>" />
												<input type="hidden" name="CourseID" value="<cfoutput>#rs_task.cid#</cfoutput>" />
												<input type="hidden" name="Title" value="《<cfoutput>#rs_task.course_name#</cfoutput>》- 主讲教师: <cfoutput>#rs_task.tch_name#</cfoutput>" />

												<input type="hidden" name="TID" value="<cfoutput>#termId#</cfoutput>" />
												<input type="hidden" name="SCC" value="<cfoutput>#chooserId#</cfoutput>" />
												<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
												
												<div class="label">
													<textarea class="comment" name="CourseComment" id="CourseComment" verification="required"></textarea>
													<p class="notice2">如果没有建议, 请填写 "无"；  填写建议字数不少于10 </p>
												</div>
												<div class="lable">
													<input id="postTrigger" <cfif targetNeed gt targetDone>disabled="disabled"</cfif> class="button <cfif targetNeed gt targetDone>disabled</cfif>" type="submit" value="提交评价表" />
												</div>
											</form>
										</td>
									</tr>
								
								</table>
								
							</cfif>
							
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								
								function postScroll( quota, hash ) {

									var mark = $("input#Mark" + quota).val();
									var re = /^[-\+]?\d+$/;
									
									if ( re.test(mark) ) {
										
										var opt = parseInt(mark);
										
										if ( opt >=60 && opt <= 100 ) {
										
											/* 显示阻挡信息 */
											$.blockUI({ 
													message: '正在保存...',
													css: { 
															'width': '16%', 
															'left': '42%', 
															'border': 'none', 
															'padding': '15px 5px', 
															'backgroundColor': '#FFF', 
															'border-radius': '4px', 
															'opacity': .8, 
															'color': '#333', 
															'cursor': null
															},
													overlayCSS: {
															'backgroundColor': '#fff', 
															'opacity': .1 ,
															'cursor': null
															}
													}); 
											
											/* 异步提交投票数据 */
											$.post(
													"<cfoutput>#buildURL('apiPostScroll')#</cfoutput>", 
													{
														'TAG' : quota,
														'OPT' : opt,
														'ST' : hash, 
														'SCC' : '<cfoutput>#chooserId#</cfoutput>',
														'seed': (new Date()).getTime()
													}, 
													function(data) {
										
														//$("#out").html(data);
										
														result = $.parseJSON(data);
										
														if ( result.success ) {
											
															/* 移除选中标记 */
															$("input#Mark" + quota).val(result.mark)
											
															/* 检查问卷是否完成 */
															var optNeed = <cfoutput>#targetNeed#</cfoutput>;
															var optDone = parseInt( result.optDone );
											
															if ( optNeed == optDone ) {
																$("input#postTrigger").removeAttr("disabled").removeClass("disabled");
															}
											
															/* 取消阻挡 */
															$.unblockUI();

														}
														else {
															
															alert(result.reason);
															
															/* 取消阻挡 */
															$.unblockUI();
														}
										
													});
											
										
										}
										else {
											$("input#Mark" + quota).focus();
										}
										
									}
									else {
										$("input#Mark" + quota).focus();
									}
									
								}

								function postQuota( quota, opt, hash ) {
							
									/* 显示阻挡信息 */
									$.blockUI({ 
										message: '正在保存...',
										css: { 
												'width': '16%', 
												'left': '42%', 
												'border': 'none', 
												'padding': '15px 5px', 
												'backgroundColor': '#FFF', 
												'border-radius': '4px', 
												'opacity': .8, 
												'color': '#333', 
												'cursor': null
												},
										overlayCSS: {
												'backgroundColor': '#fff', 
												'opacity': .1 ,
												'cursor': null
												}
										}); 
							
									/* 异步提交投票数据 */
									$.post(
											"<cfoutput>#buildURL('apiPostQuota')#</cfoutput>", 
											{
												'TAG' : quota,
												'OPT' : opt,
												'ST' : hash, 
												'SCC' : '<cfoutput>#chooserId#</cfoutput>',
												'seed': (new Date()).getTime()
											}, 
											function(data) {
										
												//$("#out").html(data);
										
												result = $.parseJSON(data);
										
												if ( result.success ) {
											
													/* 移除选中标记 */
													$("a[data-opt]", $("td.quota[rowid='" + quota + "']")).removeClass("checked");
													/* 添加对应选中标记 */
													$("a[data-opt='" + opt + "']", $("td.quota[rowid='" + quota + "']")).addClass("checked");
											
													/* 检查问卷是否完成 */
													var optNeed = <cfoutput>#targetNeed#</cfoutput>;
													var optDone = parseInt( result.optDone );
											
													if ( optNeed == optDone ) {
														$("input#postTrigger").removeAttr("disabled").removeClass("disabled");
													}
											
													/* 取消阻挡 */
													$.unblockUI();

												}
												else {
													
													alert(result.reason);
													
													/* 取消阻挡 */
													$.unblockUI();
												}
										
											});
							
									}
								
								// -->
								//]]>
							</script>

							
							
						<cfelse>
							<div class="systemNotice">
								<h3>不是评教时间</h3>
								<p class="mln">该门课程目前不允许进行网上评价, 谢谢您的关注</p>
							</div>
					</cfif>
					
				</div>
				
				
				
			</div>
		</li>
	</ul>
</div>


